<?php
/**
 * Clase dedicada a la revisión de datos de usuario en la base de datos
 * @author frimost(Armandux)
 * @copyright glp3
 * @version 0.0.1
 *
 */
class Sentinel{
	private $setter;
	private $nick;
	private $password;
	private $pase;//Permiso de acceso, puede ser false o true
	
	private $id;
	private $idPase;
	private $dbOperator;
	
	function __construct(){
		$this->setter=new Setter("../../Config");

		$this->nick="";
		$this->password="";
		$this->pase=false;
		
		$this->id="";
		$this->idPase="";
				
		$this->dbOperator=new DbOperator($host="".$this->setter->getDataBaseHost()."", $userName="".$this->setter->getDataBaseUserName()."", $dbName="".$this->setter->getDataBaseName()."", $password="".$this->setter->getDataBasePassword()."");
	}
	
	//Gets y sets
		
	//-----------

	function NickPasswordVerify($nick="", $password="",$tableName, $nickFieldName="", $passwordFieldName=""){
		$this->nick=$nick;
		$this->password=$password;
		//Conectar a la base de datos
		$this->dbOperator->connect();
	
		//Hacer la consulta
		$respConsult=$this->dbOperator->consult("SELECT ".$passwordFieldName." FROM ".$tableName." WHERE ".$nickFieldName."='".$this->nick."'","yes");
		
		if ($respConsult[0]==$this->password){
			$this->pase=true;
		}
		else{
			$this->pase=false;
		}
		return $this->pase;
	}
	
	function idVerify($id="", $tableName="", $idFieldName=""){
		$this->id=$id;
		
		$this->dbOperator->connect();
		
		$respConsult=$this->dbOperator->consult("SELECT ".$idFieldName." FROM ".$tableName." WHERE ".$idFieldName."='".$this->id."'","yes");
		if($respConsult[0]==$this->id){
			$this->idPase=true;
		}
		else{
			$this->idPase=false;
		}
		return $this->idPase;
	}
	
} 
?>
